/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GUI_OpcionesInicio.java
 *
 * Created on 18-nov-2009, 19:54:47
 */
package GUI;

import Controlador.Controlador;
import Modelo.Idiomas.LocaleManager;
import Modelo.Alertas;
import java.awt.Dimension;
import java.awt.Toolkit;

/**
 *
 * @author Administrador
 */
public class GUI_Configuracion extends javax.swing.JDialog {

    private static Controlador controlador;
    private boolean modoMapas;
    private String idioma;
    private String cuentaGoogle;
    private int puertoSerie;

    /** Creates new form GUI_OpcionesInicio */
    public GUI_Configuracion(java.awt.Frame parent) {
        super(parent, true);
        controlador = InicioAplicacion.getControlador();
        initComponents();
        cambioIdioma();
        centrarAplicacion();
        setDefaultCloseOperation(0);
        recordarOpcionesAntiguas();
        setVisible(true);
    }

    private void centrarAplicacion() {
        int width = this.getWidth();
        int height = this.getHeight();
        Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
        int x = (screen.width - width) / 2;
        int y = (screen.height - height) / 2;
        setBounds(x, y, width, height);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        BGMapas = new javax.swing.ButtonGroup();
        BGIdioma = new javax.swing.ButtonGroup();
        BAceptar = new javax.swing.JButton();
        POpciones = new javax.swing.JPanel();
        RBEspanol = new javax.swing.JRadioButton();
        LPuertoSerie = new javax.swing.JLabel();
        RBMemoria = new javax.swing.JRadioButton();
        RBIngles = new javax.swing.JRadioButton();
        TXTPuertoSerie = new javax.swing.JTextField();
        RBGoogle = new javax.swing.JRadioButton();
        jSeparator1 = new javax.swing.JSeparator();
        jSeparator2 = new javax.swing.JSeparator();
        LCuentaGoogle = new javax.swing.JLabel();
        TXTCuentaGoogle = new javax.swing.JTextField();
        jSeparator3 = new javax.swing.JSeparator();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("");
        setBounds(new java.awt.Rectangle(0, 0, 0, 0));
        setResizable(false);

        BAceptar.setBackground(new java.awt.Color(102, 153, 255));
        BAceptar.setForeground(new java.awt.Color(0, 51, 204));
        BAceptar.setText("Aceptar");
        BAceptar.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED, java.awt.Color.blue, java.awt.Color.blue, java.awt.Color.blue, java.awt.Color.blue));
        BAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BAceptarActionPerformed(evt);
            }
        });

        POpciones.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(new java.awt.Color(102, 153, 255), 3, true), "Opciones", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.TOP, new java.awt.Font("Arial", 1, 14), new java.awt.Color(102, 153, 255))); // NOI18N

        BGIdioma.add(RBEspanol);
        RBEspanol.setText("Español");

        LPuertoSerie.setText("Puerto Serie: ");

        BGMapas.add(RBMemoria);
        RBMemoria.setText("Disco duro");

        BGIdioma.add(RBIngles);
        RBIngles.setText("Inglés");

        TXTPuertoSerie.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        TXTPuertoSerie.setText("2");

        BGMapas.add(RBGoogle);
        RBGoogle.setText("Google Maps");

        LCuentaGoogle.setText("Cuenta Google:");

        TXTCuentaGoogle.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        TXTCuentaGoogle.setText("ABQIAAAAP7mVZDMT-Vpal7TCFldcLhRk-Hwz9c_--F2C22uANDjvYyeKKhRhSeYspl4gJgmqsRrqzQ-lnEgTlg");

        javax.swing.GroupLayout POpcionesLayout = new javax.swing.GroupLayout(POpciones);
        POpciones.setLayout(POpcionesLayout);
        POpcionesLayout.setHorizontalGroup(
            POpcionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(POpcionesLayout.createSequentialGroup()
                .addGroup(POpcionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(POpcionesLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(POpcionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(LPuertoSerie, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(RBMemoria, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(RBIngles, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(POpcionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(POpcionesLayout.createSequentialGroup()
                                .addGap(154, 154, 154)
                                .addComponent(TXTPuertoSerie, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(POpcionesLayout.createSequentialGroup()
                                .addGap(152, 152, 152)
                                .addComponent(RBGoogle, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(POpcionesLayout.createSequentialGroup()
                                .addGap(153, 153, 153)
                                .addComponent(RBEspanol, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addComponent(jSeparator2, javax.swing.GroupLayout.DEFAULT_SIZE, 625, Short.MAX_VALUE)
                    .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 625, Short.MAX_VALUE)
                    .addGroup(POpcionesLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(LCuentaGoogle, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(TXTCuentaGoogle, javax.swing.GroupLayout.PREFERRED_SIZE, 275, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(236, 236, 236))
                    .addComponent(jSeparator3, javax.swing.GroupLayout.DEFAULT_SIZE, 625, Short.MAX_VALUE))
                .addContainerGap())
        );
        POpcionesLayout.setVerticalGroup(
            POpcionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(POpcionesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(POpcionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(RBMemoria)
                    .addComponent(RBGoogle))
                .addGap(18, 18, 18)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(POpcionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(RBIngles)
                    .addComponent(RBEspanol))
                .addGap(29, 29, 29)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(POpcionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(LPuertoSerie)
                    .addComponent(TXTPuertoSerie, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(30, 30, 30)
                .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(POpcionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(LCuentaGoogle)
                    .addComponent(TXTCuentaGoogle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(77, 77, 77))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(POpciones, javax.swing.GroupLayout.PREFERRED_SIZE, 444, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(19, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(165, Short.MAX_VALUE)
                .addComponent(BAceptar, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(164, 164, 164))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(POpciones, javax.swing.GroupLayout.PREFERRED_SIZE, 361, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(BAceptar, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void BAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BAceptarActionPerformed

        if (RBGoogle.isSelected())
            modoMapas = true;
        if (RBMemoria.isSelected())
            modoMapas = false;
        if (RBEspanol.isSelected())
            idioma = "es";
        if (RBIngles.isSelected())
            idioma = "en";
        if (Integer.valueOf(TXTPuertoSerie.getText()) > 0) {
            puertoSerie = Integer.valueOf(TXTPuertoSerie.getText());
            cuentaGoogle = TXTCuentaGoogle.getText();
            LocaleManager.initLocalizationSupport(idioma);
            dispose();
        } else {
            Alertas.errorPuertoSerie(this);
        }
}//GEN-LAST:event_BAceptarActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BAceptar;
    private javax.swing.ButtonGroup BGIdioma;
    private javax.swing.ButtonGroup BGMapas;
    private javax.swing.JLabel LCuentaGoogle;
    private javax.swing.JLabel LPuertoSerie;
    private javax.swing.JPanel POpciones;
    private javax.swing.JRadioButton RBEspanol;
    private javax.swing.JRadioButton RBGoogle;
    private javax.swing.JRadioButton RBIngles;
    private javax.swing.JRadioButton RBMemoria;
    private javax.swing.JTextField TXTCuentaGoogle;
    private javax.swing.JTextField TXTPuertoSerie;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    // End of variables declaration//GEN-END:variables


    private void cambioIdioma() {
        this.setTitle(LocaleManager.getMessage("configuracionTitulo"));
        this.BAceptar.setText(LocaleManager.getMessage("configuracionAceptar"));
        this.POpciones.setBorder(
                javax.swing.BorderFactory.createTitledBorder(
                new javax.swing.border.LineBorder(
                new java.awt.Color(102, 153, 255), 3, true),
                LocaleManager.getMessage("configuracionOpciones"),
                javax.swing.border.TitledBorder.CENTER,
                javax.swing.border.TitledBorder.TOP,
                new java.awt.Font("Arial", 1, 14),
                new java.awt.Color(102, 153, 255)));
        this.LPuertoSerie.setText(LocaleManager.getMessage("configuracionPuertoSerie"));
        this.LCuentaGoogle.setText(LocaleManager.getMessage("configuracionCuentaGoogle"));
        this.RBEspanol.setText(LocaleManager.getMessage("configuracionEspanol"));
        this.RBIngles.setText(LocaleManager.getMessage("configuracionIngles"));
        this.RBMemoria.setText(LocaleManager.getMessage("configuracionHdd"));
    }

    private void recordarOpcionesAntiguas() {
        if (controlador.getIdioma().equals("es")) {
            RBEspanol.setSelected(true);
        }
        if (controlador.getIdioma().equals("en")) {
            RBIngles.setSelected(true);
        }
        if (controlador.getModoMapas()) {
            RBGoogle.setSelected(true);
        }
        else {
            RBMemoria.setSelected(true);
        }
        TXTCuentaGoogle.setText(controlador.getCuentaGoogle());
        TXTPuertoSerie.setText(String.valueOf(controlador.getPuertoSerie()));
    }

    public boolean getModoMapas() {
        return modoMapas;
    }

    public int getPuertoSerie() {
        return puertoSerie;
    }

    public String getCuentaGoogle() {
        return cuentaGoogle;
    }

    public String getIdioma() {
        return idioma;
    }
}
